package com.alan.camunda.boot.delegate;

import com.alan.camunda.boot.mapper.FooMapper;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.delegate.BpmnError;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 打印节点名称和变量值
 */
@Slf4j
@Component("pv")
public class PrintVariablesDelegate implements JavaDelegate {
    @Resource
    private FooMapper fooMapper;

    @Override
    public void execute(DelegateExecution execution) throws Exception {
        log.info("业务KEY为: {}", execution.getProcessBusinessKey());
        Map<String, Object> variables = execution.getVariables();
        // log.info("PrintVariablesDelegate 环节名称: {} , 代理类可访问变量为: \n{}", execution.getCurrentActivityName(), JSON.toJSONString(variables, true));
        log.info("环节: {} , 代理类可访问变量为: {}", execution.getCurrentActivityName(), JSON.toJSONString(variables));

        JSONObject abort = new JSONObject();
        abort.put("label", "Label1111");
        abort.put("message", "Some Message");
        execution.setVariableLocal("_abort_", abort);

        fooMapper.saveData("Hello," + System.currentTimeMillis());

        System.out.println("fooMapper.insert()");

    }



}
